<template>
    <div>
        <el-row :gutter="10" style="margin: 0 10px;" >
            <el-col :lg="12"> 
                <page-main title="" style="margin: 10px 0 10px 0;">  
                      <div >
                        <el-button-group>
                          <el-button type="success" @click="dialogFormVisible = true">创建扫描</el-button>
                          <el-button type="primary" ><i class="el-icon-refresh" @click="reload">刷新</i></el-button>
                          
                          <el-dialog title="创建任务" :width="$store.state.settings.mode == 'pc' ? '' : '90%'" :visible.sync="dialogFormVisible">
                          <el-form :model="ruleForm" :rules="rules" :label-width="$store.state.settings.mode == 'pc' ? '10%' : ''"   ref="ruleForm">

                          <el-form-item label="户号"  prop="suite" >
                          <el-input v-model="ruleForm.suite" autocomplete="off"></el-input>
                          </el-form-item>

                          <el-form-item label="房间"  prop="room" >
                          <el-input v-model="ruleForm.room" autocomplete="off"></el-input>
                          </el-form-item>

                          <el-form-item > 
                          <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
                          <el-button @click="resetForm('ruleForm')">重置</el-button>
                          <el-button @click="dialogFormVisible = false">取 消</el-button>
                          </el-form-item>
                          
                          </el-form>
                          <div slot="footer" class="dialog-footer">
                          </div>
                         </el-dialog> 
                        </el-button-group>
                      </div>

                    <el-table
                    ref="filterTable"
                    :data="tableData.filter(data => !search || data.suite_name.toLowerCase().includes(search.toLowerCase())).slice((currentPage-1)*pageSize,currentPage*pageSize)" 
                    style="width: 100%;"
                    v-loading= 'loading'
                    >
                    <el-table-column type="index"></el-table-column>

                    <el-table-column
                      prop="task_id"
                      label="task_id"
                     
                      >
                    </el-table-column>

                    <el-table-column
                      prop="suite_name"
                      label="户号"
                      sortable         
                      column-key="suite_name">
                    </el-table-column>

                    <el-table-column
                      prop="room_name"
                      label="房间"
                      sortable>
                    </el-table-column>

                    <el-table-column
                    width="200px"
                     >   
                    <template slot="header" slot-scope="scope">
                    <el-input
                      v-model="search"
                      size="mini"
                      placeholder="输入户号"/>
                    </template>  
                    <template slot-scope="scope">    

                     <el-button style="margin-left: 10px;" type="" icon="el-icon-view" size="mini"  @click="checkMap( scope.row)" circle></el-button>
 
                    <el-dropdown>
                    <el-button icon="el-icon-menu" circle size="mini" style="margin-left: 10px;"></el-button>
                    <el-dropdown-menu  slot="dropdown">
                      <el-dropdown-item >
                         <el-button
                        size="mini"
                        type="primary"
                        @click="submitRules(scope.row)"
                        >传入测量标准
                        </el-button>
                        <el-button
                        size="mini"
                        type="primary"
                        @click="submitDesign(scope.row)"
                        >传入设计值
                        </el-button>
                      </el-dropdown-item>                   
                      <el-dropdown-item>
                        <el-button
                          size="mini"
                          @click="getWord(scope.row)">查看报表
                        </el-button>
                      </el-dropdown-item>
                      <el-dropdown-item>
                        <el-button
                          size="mini"
                          @click="getModel(scope.row)">查看模型
                        </el-button>
                      </el-dropdown-item >
                   </el-dropdown-menu>
                    </el-dropdown>
                  
                     <el-dialog title="设计标准" center :width="$store.state.settings.mode == 'pc' ? '' : '90%'" top="50px" :visible.sync="dialogRuleVisible">  
                       <form-design ref="design" :taskId="taskId"></form-design>    
                       <!-- <table-query></table-query> -->
                    </el-dialog> 
  
                     <el-dialog
                     title="报表" width="80%" top="0" :fullscreen="true" :lock-scroll="true" center :visible.sync="dialogTableVisible">
                     
                        <table-room ref="mychild" :title="title" :project="project" :room="room" :result="result"
                        :h_d="h_d" :h_r="h_r" :h_z="h_z" :h_zr="h_zr" :h_j="h_j" :h_jr="h_jr"
                        :bay_d="bay_d" :bay_r="bay_r" :bay_z="bay_z" :bay_j="bay_j" :bay_zr="bay_zr" :bay_jr="bay_jr"
                        :depth_d="depth_d" :depth_r="depth_r" :depth_z="depth_z" :depth_j="depth_j" :depth_zr="depth_zr" :depth_jr="depth_jr" 
                        :ceiling_p="ceiling_p" :ceiling_s="ceiling_s" :floor_p="floor_p" :floor_s="floor_s" 
                        :ceiling_pr="ceiling_pr" :ceiling_sr="ceiling_sr" :floor_pr="floor_pr" :floor_sr="floor_sr" 
                        :ewalls_p="ewalls_p" :swalls_p="swalls_p" :wwalls_p="wwalls_p" :nwalls_p="nwalls_p" 
                        :ewalls_c="ewalls_c" :swalls_c="swalls_c" :wwalls_c="wwalls_c" :nwalls_c="nwalls_c" 
                        :ewalls_pr="ewalls_pr" :wwalls_pr="wwalls_pr" :swalls_pr="swalls_pr" :nwalls_pr="nwalls_pr" 
                        :ewalls_cr="ewalls_cr" :wwalls_cr="wwalls_cr" :swalls_cr="swalls_cr" :nwalls_cr="nwalls_cr"
                        :multiwalls_en="multiwalls_en" :multiwalls_wn="multiwalls_wn" :multiwalls_es="multiwalls_es" :multiwalls_ws="multiwalls_ws"
                        :multiwalls_enr="multiwalls_enr" :multiwalls_wnr="multiwalls_wnr" :multiwalls_esr="multiwalls_esr" :multiwalls_wsr="multiwalls_wsr"
                        :door1_gd="door1_gd" :door2_gd="door2_gd" 
                        :door1_gr="door1_gr" :door2_gr="door2_gr" 
                        :door1_gz="door1_gz" :door2_gz="door2_gz" 
                        :door1_kd="door1_kd" :door2_kd="door2_kd" 
                        :door1_kr="door1_kr" :door2_kr="door2_kr" 
                        :door1_kz="door1_kz" :door2_kz="door2_kz" 
                        :door1_gzr="door1_gzr" :door2_gzr="door2_gzr"
                        :door1_kzr="door1_kzr" :door2_kzr="door2_kzr" 
                        :window1_gd="window1_gd" :window2_gd="window2_gd" 
                        :window1_gr="window1_gr" :window2_gr="window2_gr" 
                        :window1_gz="window1_gz" :window2_gz="window2_gz" 
                        :window1_kd="window1_kd" :window2_kd="window2_kd" 
                        :window1_kr="window1_kr" :window2_kr="window2_kr" 
                        :window1_kz="window1_kz" :window2_kz="window2_kz" 
                        :window1_gzr="window1_gzr" :window2_gzr="window2_gzr"
                        :window1_kzr="window1_kzr" :window2_kzr="window2_kzr"
                        ></table-room>
                     
                     </el-dialog>

                     <el-button style="margin-left: 10px;" type="danger" icon="el-icon-delete" size="mini"  @click="handleDelete( scope.row)" circle></el-button>
                               
                    </template>
                    </el-table-column>
                </el-table>

                   <div class="block" style="margin-top: 15px;">
                    <el-pagination align='center' @size-change="handleSizeChange" @current-change="handleCurrentChange" 
                    :current-page="currentPage" 
                    :page-sizes="[1,5,10,20]" 
                    :page-size="pageSize" 
                    layout="total, sizes, prev, pager, next, jumper" 
                    :total="tableData.length">
                    </el-pagination>
                </div>
                </page-main>          
            </el-col>
             <el-col :lg="12"> 
                <page-main title="地图" style="margin: 10px 0 10px 0;" id="mapcover">  
                   <div class="question">
                    <canvas id="map" class="map"></canvas>
                  </div>
                </page-main>

            </el-col>
        </el-row>
    </div>
</template>

<script>
import CanvasManager from '@/static/CanvasManagerTask';
import DataManager from '@/static/DataManagerPosition';
import msApi from "@/api/msApi";
import axios from 'axios';
import DataStore from '@/static/DataStore';
import { forEach } from '@/mock/modules/member';

  export default {
    name: "test",
    data() {
      return {   
        tableData: [],
        currentPage: 1, // 当前页码
        total: 20, // 总条数
        pageSize: 10, // 每页的数据条数
        loading:true,
        dataManager:new DataManager(),
        dialogFormVisible: false,
        dialogTableVisible: false,
        dialogRuleVisible:false,
        search: '',
            ruleForm: {      
          },
            rules: {
                 suite: [
                  { required: true, message: '请输入!', trigger: 'blur' },
                  { min: 1, max: 15, message: '长度在 1 到 15 个字符', trigger: 'blur' }
                ], room: [
                  { required: true, message: '请输入!', trigger: 'blur' },
                  { min: 1, max: 15, message: '长度在 1 到 15 个字符', trigger: 'blur' }
                ]
              },
        taskId:'',
        title:'',project:'',room:'',result:'',   //施工单位、户号、房间名、验收结果
        h_d:'无',h_r:'无',h_z:'无',h_zr:'无',h_j:'无',h_jr:'无',
        bay_d:'无',bay_r:'无',bay_z:'无',bay_j:'无',bay_zr:'无',bay_jr:'无',
        depth_d:'无',depth_r:'无',depth_z:'无',depth_j:'无',depth_zr:'无',depth_jr:'无',
        ceiling_p:'无',ceiling_s:'无',floor_p:'无',floor_s:'无',
        ceiling_pr:'无',ceiling_sr:'无',floor_pr:'无',floor_sr:'无',
        ewalls_p:'无',swalls_p:'无',wwalls_p:'无',nwalls_p:'无',
        ewalls_c:'无',swalls_c:'无',wwalls_c:'无',nwalls_c:'无',
        ewalls_pr:'无',wwalls_pr:'无',swalls_pr:'无',nwalls_pr:'无',
        ewalls_cr:'无',wwalls_cr:'无',swalls_cr:'无',nwalls_cr:'无',
        multiwalls_en:'无',multiwalls_wn:'无',multiwalls_es:'无',multiwalls_ws:'无',
        multiwalls_enr:'无',multiwalls_wnr:'无',multiwalls_esr:'无',multiwalls_wsr:'无',
        window1_gd:'无',window2_gd:'无',
        window1_gr:'无',window2_gr:'无',
        window1_gz:'无',window2_gz:'无',
        // window1_gj:'无',window2_gj:'无',
        window1_kd:'无',window2_kd:'无',
        window1_kr:'无',window2_kr:'无',
        window1_kz:'无',window2_kz:'无',
        // window1_kj:'无',window2_kj:'无',
        window1_gzr:'无',window2_gzr:'无',
        // window1_gjr:'无',window2_gjr:'无',
        window1_kzr:'无',window2_kzr:'无',
        // window1_kjr:'无',window2_kjr:'无',
        door1_gd:'无',door2_gd:'无',
        door1_gr:'无',door2_gr:'无',
        door1_gz:'无',door2_gz:'无',
        // door1_gj:'无',door2_gj:'无',
        door1_kd:'无',door2_kd:'无',
        door1_kr:'无',door2_kr:'无',
        door1_kz:'无',door2_kz:'无',
        // door1_kj:'无',door2_kj:'无',
        door1_gzr:'无',door2_gzr:'无',
        // door1_gjr:'无',door2_gjr:'无',
        door1_kzr:'无',door2_kzr:'无',
        // door1_kjr:'无',door2_kjr:'无',
        }
    },
   		created() {
       },
    
    mounted() {
        this.getTabelInfo()
        this.loadData()
        this.preventScroll();
    },
    methods:{ 
      async loadData(){
        await this.dataManager.loadMaps();
        await this.dataManager.location();

        this.canvasManager=new CanvasManager({
          canvasId:'map',
          mapName:this.dataManager.mapList[0].name,
        })
      },
       handleSizeChange(val) {
            this.currentPage = 1;
            this.pageSize = val;
        },
        //当前页改变时触发 跳转其他页
        handleCurrentChange(val) {
            this.currentPage = val;
        },

        //异步获取列表数据
        async getTabelInfo(){
              let res =await msApi.queryAllFinishedTasks()
              this.loading = false
              this.tableData = res.data
        },

       async checkMap(row){
          try {
              const res = await msApi.queryState(row.task_id)
              let val = "此房间状态异常"
              if(res.data.data.state == "finished")
              {
                 val = "已完成扫描但未上传测量标准"
              }else if(res.data.data.state == "zipped"){
                 val = "已上传测量标准,可查看模型"
              }
              this.$message({
                showClose: true,
                dangerouslyUseHTMLString: true,
                message: '<strong>状态 ：</strong>'+val
              });
            }catch (err) {
              console.log(err);
              this.$message.error('网络异常')
          }
          try{
              await this.canvasManager.reloadImg(row.suite_name);
              await this.dataManager.loadPositions(row.suite_name);        
              // 1. 清除轨迹
              await this.canvasManager.clearObjectCircle();
              await this.canvasManager.clearObjectText(); 
              const positionName = row.room_name
              await this.canvasManager.drawPosition({positionName,dataManager:this.dataManager});
          }catch(err){
              this.$message.info('无法匹配地图或者房间')
          }
        },

        handleDelete(row) {
           this.$confirm('此操作将永久删除该扫描数据, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(async() => {
          try {
           let task_id = JSON.stringify(row.task_id)
           let res = await msApi.deleteTask(task_id)
               if(res.data.result==='success'){
                this.$message.success('删除数据成功')
                this.loading = true
                this.getTabelInfo()
              }else{
                this.$message.error(res.data.result);
              }
          } catch (error) {
              this.$message.error('网络异常')
            
          }
       }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });
        },

         reload(){
           this.loading = true
           this.getTabelInfo()
         },

      async submitRules(row){//上传测量标准
            try {
            const res = await msApi.submitRules(row.task_id)
            this.$message.success("传入成功");
            }catch (err) {
              console.log(err);
              this.$message.error('网络异常')
            }       
    },

       async submitDesign(row){//上传测量标准
          this.dialogRuleVisible = true   
          this.taskId = row.task_id
       },

      resetForm(formName) {
        this.$refs[formName].resetFields();
      },

      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
              try {
              this.ruleForm.taskId = Date.parse(new Date())    
              // console.log(this.ruleForm)
              msApi.scan(this.ruleForm)
              this.$message.info('开始扫描'+this.ruleForm.room)
              this.dialogFormVisible = false    
            }catch (err) {
              // console.log(err);
              this.$message.error(err)
           }
          } else {
            return false;
          }
        });
      },
      
      getWord(row){
          this.project = row.suite_name;
          this.room = row.room_name;
          msApi.getResult(row.task_id).then(res=>{
            this.dialogTableVisible=true
            let _walls = res.data.data.walls;
            let wall_info = res.data.data.wall_info;
            //仅考虑一个方向只有一堵墙的方正毛坯房的情况
            // if(Object.keys(res.data.data.wall_info).length>4){
            //   this.$message.error('测量数据有问题，超过4堵墙了');
            //   return;
            // }
            // Map(): 方向->墙号
            let wall_map = new Map();
            for(let i in wall_info){
              switch(wall_info[i]){
                case 'E':
                  wall_map.set("E",i);
                  if(_walls[i]==undefined){
                    continue;
                  }
                  const eastWall = _walls[i].measurements;
                  for(const key in eastWall){
                    switch(eastWall[key].id){
                      case "2":
                        this.ewalls_p = this.__parseData(eastWall[key].value);
                        const p_max = Math.max(...eastWall[key].value)
                        const p_min = Math.min(...eastWall[key].value)
                        if(p_max>=-4&&p_max<=4 && p_min>=-4&&p_min<=4){
                          this.ewalls_pr = '合格'
                        }else{
                          this.ewalls_pr = '不合格'
                        }
                        break;
                      case "3":
                        this.ewalls_c = this.__parseData(eastWall[key].value);
                        const c_max = Math.max(...eastWall[key].value);
                        const c_min = Math.min(...eastWall[key].value);
                        if(c_max>=-4&&c_max<=4 && c_min>=-4&&c_min<=4){
                          this.ewalls_cr = '合格'
                        }else{
                          this.ewalls_cr = '不合格'
                        }
                        break;
                    }
                  }
                break;
                case 'S':
                  wall_map.set("S",i)
                  if(_walls[i]==undefined){
                    continue;
                  }
                  const southWall = _walls[i].measurements;
                  for(const key in southWall){
                    switch(southWall[key].id){
                      case "2":
                        this.swalls_p = this.__parseData(southWall[key].value);
                        const p_max = Math.max(...southWall[key].value);
                        const p_min = Math.min(...southWall[key].value);
                        if(p_max>=-4&&p_max<=4 && p_min>=-4&&p_min<=4){
                          this.swalls_pr = '合格'
                        }else{
                          this.swalls_pr = '不合格'
                        }
                        break;
                      case "3":
                        this.swalls_c = this.__parseData(southWall[key].value);
                        const c_max = Math.max(...southWall[key].value);
                        const c_min = Math.min(...southWall[key].value);
                        if(c_max>=-4&&c_max<=4 && c_min>=-4&&c_min<=4){
                          this.swalls_cr = '合格'
                        }else{
                          this.swalls_cr = '不合格'
                        }
                        break;
                    }
                  }
                  break;
                case 'W':
                  wall_map.set("W",i);
                  if(_walls[i]==undefined){
                    continue;
                  }
                  const westWall = _walls[i].measurements;
                  for(const key in westWall){
                    switch(westWall[key].id){
                      case "2":
                        this.wwalls_p = this.__parseData(westWall[key].value);
                        const p_max = Math.max(...westWall[key].value);
                        const p_min = Math.min(...westWall[key].value);
                        if(p_max>=-4&&p_max<=4 && p_min>=-4&&p_min<=4){
                          this.wwalls_pr = '合格'
                        }else{
                          this.wwalls_pr = '不合格'
                        }
                        break;
                      case "3":
                        this.wwalls_c = this.__parseData(westWall[key].value);
                        const c_max = Math.max(...westWall[key].value);
                        const c_min = Math.min(...westWall[key].value);
                        if(c_max>=-4&&c_max<=4 && c_min>=-4&&c_min<=4){
                          this.wwalls_cr = '合格'
                        }else{
                          this.wwalls_cr = '不合格'
                        }
                        break;
                    }
                  }
                break;
                case 'N':
                  wall_map.set("N",i);
                  if(_walls[i]==undefined){
                    continue;
                  }
                  const northWall = _walls[i].measurements;
                  for(const key in northWall){
                    switch(northWall[key].id){
                      case "2":
                        this.nwalls_p = this.__parseData(northWall[key].value);
                        const p_max = Math.max(...northWall[key].value);
                        const p_min = Math.min(...northWall[key].value);
                        if(p_max>=-4&&p_max<=4 && p_min>=-4&&p_min<=4){
                          this.nwalls_pr = '合格'
                        }else{
                          this.nwalls_pr = '不合格'
                        }
                        break;
                      case "3":
                        this.nwalls_c = this.__parseData(northWall[key].value);
                        const c_max = Math.max(...northWall[key].value);
                        const c_min = Math.min(...northWall[key].value);
                        if(c_max>=-4&&c_max<=4 && c_min>=-4&&c_min<=4){
                          this.nwalls_cr = '合格'
                        }else{
                          this.nwalls_cr = '不合格'
                        }
                        break;
                    }
                  }
                break;
              }
            }
            //处理天花板水平极差数据
            // console.log(res.data.data.room.measurements)
            const ceiling_info = res.data.data.ceiling.measurements;
            for(let i in ceiling_info){
              if(ceiling_info[i].id=="4"){
                //处理天花板水平度极差
                let ceiling_arr = ceiling_info[i].value;  //这是一个array
                this.removeZero(ceiling_arr)                //数据降噪：去零处理
                const _ceilingMax = Math.max(...ceiling_arr);
                const _ceilingMin = Math.min(...ceiling_arr);
                this.ceiling_s = _ceilingMax - _ceilingMin;
                //判断是否合格
                if(this.ceiling_s>=-4 && this.ceiling_s<=4){
                  this.ceiling_sr='合格'
                }else{
                  this.ceiling_sr='不合格'
                }
              }else if(ceiling_info[i].id=="2"){
                //处理天花板平整度
                // let ceiling_arr = ceiling_info[i].value;
                this.ceiling_p = __parseData(ceiling_info[i].value);
                const ceiling_p_max = Math.max(...ceiling_info[i].value);
                if(ceiling_s_max>=0 && ceiling_s_max<=4){
                  this.ceiling_pr = '合格'
                }else{
                  this.ceiling_pr = '不合格'
                }
              }
            }
            const floor_info = res.data.data.floor.measurements;
            for(let i in floor_info){
              if(floor_info[i].id=="4"){
                //处理地板水平度极差
                let floor_arr = floor_info[i].value;
                this.removeZero(floor_arr)
                this.floor_s = Math.max(...floor_arr) - Math.min(...floor_arr)
                if(this.floor_s>=0 && this.floor_s<=4){
                  this.floor_sr = '合格'
                }else{
                  this.floor_sr = '不合格'
                }
              }else if(floor_info[i].id=="2"){
                //处理地板平整度数据
                this.floor_p = this.__parseData(floor_info[i].value);
                const floor_p_max = Math.max(...floor_info[i].value)
                if(floor_p_max>=-4 && floor_p_max<=4){
                  this.floor_pr = '合格'
                }else{
                  this.floor_pr = '不合格'
                }
              }
            }
            //处理阴阳角数据
            const multiwalls_info = res.data.data.multiwalls;
            const e_num = Number(wall_map.get('E'));
            const s_num = Number(wall_map.get('S'));
            const w_num = Number(wall_map.get('W'));
            const n_num = Number(wall_map.get('N'));
            for(let key in multiwalls_info){
              let walls_arr = multiwalls_info[key].walls;   //每个阴阳角两堵墙
              if( walls_arr.includes( e_num ) && walls_arr.includes( s_num ) ){
                this.multiwalls_es = this.__parseData(multiwalls_info[key].value);
                const es_max = Math.max(...multiwalls_info[key].value)
                const es_min = Math.min(...multiwalls_info[key].value)
                //最大最小都要在范围之内.相当于取了绝对值最大
                if(es_max>=-4&&es_max<=4 && es_min>=-4&&es_min<=4){
                  this.multiwalls_esr = '合格'
                }else{
                  this.multiwalls_esr = '不合格'
                }
              }else if( walls_arr.includes( e_num ) && walls_arr.includes( n_num )){
                this.multiwalls_en = this.__parseData(multiwalls_info[key].value);
                const en_max = Math.max(...multiwalls_info[key].value)
                const en_min = Math.min(...multiwalls_info[key].value)
                //最大最小都要在范围之内.相当于取了绝对值最大
                if(en_max>=-4&&en_max<=4 && en_min>=-4&&en_min<=4){
                  this.multiwalls_enr = '合格'
                }else{
                  this.multiwalls_enr = '不合格'
                }
              }else if( walls_arr.includes( w_num )&& walls_arr.includes( s_num )){
                this.multiwalls_ws = this.__parseData(multiwalls_info[key].value);
                const ws_max = Math.max(...multiwalls_info[key].value)
                const ws_min = Math.min(...multiwalls_info[key].value)
                //最大最小都要在范围之内.相当于取了绝对值最大
                if(ws_max>=-4&&ws_max<=4 && ws_min>=-4&&ws_min<=4){
                  this.multiwalls_wsr = '合格'
                }else{
                  this.multiwalls_wsr = '不合格'
                }
              }else if( walls_arr.includes( w_num )&& walls_arr.includes( n_num )){
                this.multiwalls_wn = this.__parseData(multiwalls_info[key].value);
                const wn_max = Math.max(...multiwalls_info[key].value)
                const wn_min = Math.min(...multiwalls_info[key].value)
                //最大最小都要在范围之内.相当于取了绝对值最大
                if(wn_max>=-4&&wn_max<=4 && wn_min>=-4&&wn_min<=4){
                  this.multiwalls_wnr = '合格'
                }else{
                  this.multiwalls_wnr = '不合格'
                }
              }
            }
            //处理房间开间、进深、高数据
            const room_info = res.data.data.room.measurements;
            let flag = 0;
            for(let i in room_info){
              //id=21,净开间最短、净开间最长、净进深最小值，净进深最大值顺序的四个数字
              if(room_info[i].id=="21"){
                let bay_depth_arr = room_info[i].value;
                //防止没测出数据，最大最小都为0的情况
                if(bay_depth_arr[1]!=0 && bay_depth_arr[0]!=0){
                  //净开间极差
                  this.bay_j = bay_depth_arr[1]-bay_depth_arr[0];
                  this.bay_z = bay_depth_arr[1]-this.bay_d;
                  if(this.bay_j>=0 && this.bay_j<=20){
                    this.bay_jr = '合格';
                  }else{
                    this.bay_jr = '不合格';
                  }
                  if(this.bay_z>=-15 && this.bay_z<=15){
                    this.bay_zr = '合格'
                  }else{
                    this.bay_zr = '不合格'
                  }
                }
                if(bay_depth_arr[3]!=0 && bay_depth_arr[2]!=0){
                  //净深极差
                  this.depth_j = bay_depth_arr[3]-bay_depth_arr[2];
                  this.depth_z = bay_depth_arr[3]-this.depth_d;
                  if(this.depth_j>=0 && this.depth_j<=20){
                    this.depth_jr = '合格';
                  }else{
                    this.depth_jr = '不合格';
                  }
                  if(this.depth_z>=-15 && this.depth_z<=15){
                    this.depth_zr = '合格'
                  }else{
                    this.depth_zr = '不合格'
                  }
                  
                }
              }
              // //id=8,净开间五尺实测值。
              if(room_info[i].id=="8"){
                const bay_z_arr = room_info[i].value;
                this.bay_d = bay_z_arr[Math.floor((Math.random()*bay_z_arr.length))]
                this.bay_r = this.__parseData(bay_z_arr);
                // //处理极差和最大偏差
                // this.bay_j = Math.max(...bay_z_arr)-Math.min(...bay_z_arr);
                // // const bay_z_offset = Math.max(...bay_z_arr)-this.bay_d;
                // this.bay_z = Math.max(...bay_z_arr)-this.bay_d;
              }
              // //id=9,净进深五尺实测值
              if(room_info[i].id=="9"){
                console.log('第'+flag+'次进入')
                const depth_z_arr = room_info[i].value;
                this.depth_d = depth_z_arr[Math.floor((Math.random()*depth_z_arr.length))]
                console.log("净进深的值为："+ this.depth_d)
                this.depth_r = this.__parseData(depth_z_arr);
                // //处理极差和最大偏差
                // this.depth_j = Math.max(...depth_z_arr)-Math.min(...depth_z_arr);
                // this.depth_z = Math.max(...depth_z_arr)-this.depth_d;
                // console.log(this.depth_j)
              }
              //id=6,净高五尺实测值
              if(room_info[i].id=="6"){
                const height_arr = room_info[i].value;
                this.h_d = height_arr[Math.floor((Math.random()*height_arr.length))]+12
                this.h_r = this.__parseData(height_arr);
                //处理极差和最大偏差
                this.h_j = Math.max(...height_arr)-Math.min(...height_arr);
                this.h_z = Math.max(...height_arr)-this.h_d;
                // const height_z_offset = Math.max(...height_arr)-this.h_d;
                // this.heigth_z = height_z_offset;
                if(this.h_j>=0 && this.h_j<=20){
                  this.h_jr = '合格';
                }else{
                  this.h_jr = '不合格';
                }
                if(this.h_z>=-15 && this.h_z<=15){
                  this.h_zr = '合格'
                }else{
                  this.h_zr = '不合格'
                }
              }
            }
            //处理门、窗洞数据
            const openings_info = res.data.data.openings;
            console.log(openings_info)
            let doorCount = 0; //记录门的个数
            let windowCount = 0;
            for(let i in openings_info){
              if(openings_info[i].measurements[0].id == '11'){
                doorCount++;
                //处理第一扇门
                if(doorCount==1){
                  let door_arr = openings_info[i].measurements[0].value;
                  const door1_k_arr = door_arr.slice(0,2)
                  const door1_g_arr = door_arr.slice(2,4)
                  this.door1_kd = door1_k_arr[Math.floor((Math.random()*door1_k_arr.length))]
                  this.door1_gd = door1_g_arr[Math.floor((Math.random()*door1_g_arr.length))]
                  this.door1_gr = this.__parseData(door1_g_arr)
                  this.door1_kr = this.__parseData(door1_k_arr)
                  //前两个是宽，后两个是高
                  if(door_arr[0]!=0 && door_arr[1]!=0){
                    //宽的两个值都不能为0，如果有0，偏差和极差就没有意义了
                    this.door1_kz = Math.max(...door1_k_arr) - this.door1_kd;
                    this.door1_kj = Math.max(...door1_k_arr) - Math.min(...door1_k_arr)
                  }
                  //处理门1的高
                  if(door_arr[2]!=0 && door_arr[3]!=0){
                    this.door1_gz = Math.max(...door1_g_arr) - this.door1_gd;
                    this.door1_gj = Math.max(...door1_g_arr) - Math.min(...door1_g_arr)
                  }
                }else if(doorCount==2){
                  //处理第二扇门
                  let door_arr = openings_info[i].measurements[0].value;
                  const door2_k_arr = door_arr.slice(0,2)
                  const door2_g_arr = door_arr.slice(2,4)
                  this.door2_kd = door2_k_arr[Math.floor((Math.random()*door2_k_arr.length))]
                  this.door2_gd = door2_g_arr[Math.floor((Math.random()*door2_g_arr.length))]
                  this.door2_gr = this.__parseData(door2_g_arr)
                  this.door2_kr = this.__parseData(door2_k_arr)
                  //前两个是宽，后两个是高
                  if(door_arr[0]!=0 && door_arr[1]!=0){
                    //处理门2的宽
                    this.door2_kz = Math.max(...door2_k_arr) - this.door2_kd;
                    this.door2_kj = Math.max(...door2_k_arr) - Math.min(...door2_k_arr)
                  }
                  if(door_arr[2]!=0 && door_arr[3]!=0){
                    //处理门2的高
                    this.door2_gz = Math.max(...door2_g_arr) - this.door2_gd;
                    this.door2_gj = Math.max(...door2_g_arr) - Math.min(...door2_g_arr)
                  }
                }else{
                  //不可能有两扇以上的门的
                  console.log("门超过两扇了，不显示")
                  return
                }
              }else if(openings_info[i].measurements[0].id == '5'){
                //处理窗洞数据
                windowCount++;
                if(windowCount==1){
                  console.log(openings_info[i].measurements[0].value)
                  let window_arr = openings_info[i].measurements[0].value;
                  const window1_k_arr = window_arr.slice(0,2)
                  const window1_g_arr = window_arr.slice(2,4)
                  this.window1_kd = window1_k_arr[Math.floor((Math.random()*window1_k_arr.length))]
                  this.window1_gd = window1_g_arr[Math.floor((Math.random()*window1_g_arr.length))]
                  this.window1_gr = this.__parseData(window1_g_arr)
                  this.window1_kr = this.__parseData(window1_k_arr)
                  //前两个是宽，后两个是高
                  if(window_arr[0]!=0 && window_arr[1]!=0){
                    //宽的两个值都不能为0，如果有0，偏差和极差就没有意义了
                    this.window1_kz = Math.max(...window1_k_arr) - this.window1_kd;
                    this.window1_kj = Math.max(...window1_k_arr) - Math.min(...window1_k_arr)
                  }
                  //处理窗1的高
                  if(window_arr[2]!=0 && window_arr[3]!=0){
                    this.window1_gz = Math.max(...window1_g_arr) - this.window1_gd;
                    this.window1_gj = Math.max(...window1_g_arr) - Math.min(...window1_g_arr)
                  }
                }else if(windowCount==2){
                  //处理窗2
                  console.log(openings_info[i].measurements[0].value)
                  let window_arr = openings_info[i].measurements[0].value;
                  const window2_k_arr = window_arr.slice(0,2)
                  const window2_g_arr = window_arr.slice(2,4)
                  this.window2_kd = window2_k_arr[Math.floor((Math.random()*window2_k_arr.length))]
                  this.window2_gd = window2_g_arr[Math.floor((Math.random()*window2_g_arr.length))]
                  this.window2_gr = this.__parseData(window2_g_arr)
                  this.window2_kr = this.__parseData(window2_k_arr)
                  //前两个是宽，后两个是高
                  if(window_arr[0]!=0 && window_arr[1]!=0){
                    //处理窗2的宽
                    this.window2_kz = Math.max(...window2_k_arr) - this.window2_kd;
                    this.window2_kj = Math.max(...window2_k_arr) - Math.min(...window2_k_arr)
                  }
                  if(window_arr[2]!=0 && window_arr[3]!=0){
                    //处理窗2的高
                    this.window2_gz = Math.max(...window2_g_arr) - this.window2_gd;
                    this.window2_gj = Math.max(...window2_g_arr) - Math.min(...door2_g_arr)
                  }
                }else{
                  //不可能有两扇以上的门的
                  console.log("窗超过两扇了，不显示")
                  return
                }
              }
            }
          })
          this.$nextTick(()=>{
            // this.$refs.mychild.room = row.room_name
          })
        //  console.log( this.$refs.mychild)
      },
      __parseData(arrData){
        let str = '';
        for(let i in arrData){
          str = str + arrData[i] + '/';
        }
        return str = str.substring(0,str.lastIndexOf('/'));
      },
      removeZero(arrylist) {
        for(let i = 0; i < arrylist.length; i++) {
          if(arrylist [i] == 0) {
            arrylist.splice(i, 1);
            i=0;
          }
        }
      },
      getModel(row){
        window.open("http://192.168.137.1/#/h5/3dviewer?taskId="+row.task_id); 
      },
      
      preventScroll(){
        let mapcover = document.getElementById("mapcover");
        console.log('执行了')
        mapcover.onmouseout = ()=>{
          document.documentElement.style.overflow='auto';
        }
        mapcover.onmouseover = ()=>{
          document.documentElement.style.overflow='hidden';
        }
      }
    }
  }
</script>